﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TCM.Controllers
{
    public class LevelController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /Level/

        public ActionResult Index()
        {
            var levelbases = db.LEVELBASEs.Include(l => l.MAPSTRINGBASE).Include(l => l.USERBASE).Include(l => l.USERBASE1).Include(l => l.USERBASE2);
            return View(levelbases.ToList());
        }

        //
        // GET: /Level/Details/5

        public ActionResult Details(Guid? id = null)
        {
            LEVELBASE levelbase = db.LEVELBASEs.Find(id);
            if (levelbase == null)
            {
                return HttpNotFound();
            }
            return View(levelbase);
        }

        //
        // GET: /Level/Create

        public ActionResult Create()
        {
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE");
            ViewBag.CREATEDBY = new SelectList(db.USERBASEs, "USERID", "NAME");
            ViewBag.MODIFIEDBY = new SelectList(db.USERBASEs, "USERID", "NAME");
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME");
            return View();
        }

        //
        // POST: /Level/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(LEVELBASE levelbase)
        {
            if (ModelState.IsValid)
            {
                levelbase.LEVELID = Guid.NewGuid();
                db.LEVELBASEs.Add(levelbase);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", levelbase.STATUSID);
            ViewBag.CREATEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.CREATEDBY);
            ViewBag.MODIFIEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.MODIFIEDBY);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.OWNERID);
            return View(levelbase);
        }

        //
        // GET: /Level/Edit/5

        public ActionResult Edit(Guid? id = null)
        {
            LEVELBASE levelbase = db.LEVELBASEs.Find(id);
            if (levelbase == null)
            {
                return HttpNotFound();
            }
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", levelbase.STATUSID);
            ViewBag.CREATEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.CREATEDBY);
            ViewBag.MODIFIEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.MODIFIEDBY);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.OWNERID);
            return View(levelbase);
        }

        //
        // POST: /Level/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(LEVELBASE levelbase)
        {
            if (ModelState.IsValid)
            {
                db.Entry(levelbase).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", levelbase.STATUSID);
            ViewBag.CREATEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.CREATEDBY);
            ViewBag.MODIFIEDBY = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.MODIFIEDBY);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", levelbase.OWNERID);
            return View(levelbase);
        }

        //
        // GET: /Level/Delete/5

        public ActionResult Delete(Guid? id = null)
        {
            LEVELBASE levelbase = db.LEVELBASEs.Find(id);
            if (levelbase == null)
            {
                return HttpNotFound();
            }
            return View(levelbase);
        }

        //
        // POST: /Level/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(Guid id)
        {
            LEVELBASE levelbase = db.LEVELBASEs.Find(id);
            db.LEVELBASEs.Remove(levelbase);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}